
#include "math_utils.h"
#include <math.h>

uint64_t fibonacci(uint32_t n) {
    if (n <= 1) {
        return n;
    }
    
    uint64_t a = 0, b = 1, c;
    for (uint32_t i = 2; i <= n; i++) {
        c = a + b;
        a = b;
        b = c;
    }
    return b;
}

int is_prime(uint32_t n) {
    if (n <= 1) return 0;
    if (n <= 3) return 1;
    if (n % 2 == 0 || n % 3 == 0) return 0;
    
    for (uint32_t i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) {
            return 0;
        }
    }
    return 1;
}

uint32_t gcd(uint32_t a, uint32_t b) {
    while (b != 0) {
        uint32_t temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

void vector_add(const double* a, const double* b, double* c, uint32_t size) {
    for (uint32_t i = 0; i < size; i++) {
        c[i] = a[i] + b[i];
    }
}